#!/bin/bash

# 停止并禁用 NFS 相关服务
systemctl stop nfs-server nfs-lock nfs-idmap 2>/dev/null
systemctl disable nfs-server nfs-lock nfs-idmap 2>/dev/null

# 卸载所有 NFS 相关包（兼容 dnf/yum/apt）
if command -v dnf >/dev/null 2>&1; then
    dnf remove -y $(rpm -qa | grep -E '^nfs-utils|^nfs4-acl-tools') 2>/dev/null
elif command -v yum >/dev/null 2>&1; then
    yum remove -y $(rpm -qa | grep -E '^nfs-utils|^nfs4-acl-tools') 2>/dev/null
elif command -v apt-get >/dev/null 2>&1; then
    apt-get purge -y nfs-kernel-server nfs-common 2>/dev/null
fi

# 验证
if rpm -qa 2>/dev/null | grep -qE '^nfs-utils|^nfs4-acl-tools' || dpkg -l 2>/dev/null | grep -qE 'nfs-kernel-server|nfs-common'; then
    echo "[-] NFS 服务包仍然存在"
    exit 1
else
    echo "[+] NFS 服务相关包已卸载"
    exit 0
fi